﻿@model KM.ENT.entSanPham

@{
    ViewBag.Title = "edit";
    Layout = "~/Areas/Admin/Views/Shared/MasterAdmin.cshtml";
}

<div class="row">

    <div class="col-lg-12">
        <div class="box">
            <div class="box-header">
                <h2><i class="fa fa-edit"></i>Chi tiết sản phẩm</h2>
                <div class="box-icon">
                    <a href="form-elements.html#" class="btn-setting"><i class="fa fa-wrench"></i></a>
                    <a href="form-elements.html#" class="btn-minimize"><i class="fa fa-chevron-up"></i></a>
                    <a href="form-elements.html#" class="btn-close"><i class="fa fa-times"></i></a>
                </div>
            </div>
            <div class="box-content">
                @using (Html.BeginForm("edit", "sanpham", FormMethod.Post, new { @class = "form-horizontal", enctype = "multipart/form-data" }))
                {
                    @Html.AntiForgeryToken()
                    @Html.ValidationSummary(true)
                    <table class="table">
                        <tbody>
                            <tr>
                                <td>
                                    <label class="control-label" for="focusedInput">Loại sản phẩm</label>
                                </td>
                                <td>
                                    @Html.DropDownListFor(m => m.LoaiSanPhamId, new SelectList(ViewBag.lstLKM, "Id", "TenNhomSanPham"), "===Chọn loại sản phẩm===")
                                    @Html.ValidationMessageFor(model => model.TenSanPham)

                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <label class="control-label" for="focusedInput">Tên sản phẩm</label>
                                </td>
                                <td>

                                    @Html.HiddenFor(t => t.Id)
                                    @Html.TextBoxFor(model => model.TenSanPham, new { @class = "form-control focused" })
                                    @Html.ValidationMessageFor(model => model.TenSanPham)

                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <label class="control-label" for="focusedInput">Thứ tự</label>
                                </td>
                                <td>

                                    @Html.TextBoxFor(model => model.ThuTu, new { @class = "form-control focused" })
                                    @Html.ValidationMessageFor(model => model.ThuTu)

                                </td>
                            </tr>
                            <tr>
                                <td><label class="control-label" for="focusedInput">Miêu tả tóm tắt</label></td>
                                <td>
                                    <div class="form-group">

                                        <div class="controls">
                                            @Html.TextAreaFor(model => model.MoTa, new { @class = "adminRichText" })
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td><label class="control-label" for="focusedInput">Nội dung</label></td>
                                <td>

                                    <div class="controls">
                                        @Html.TextAreaFor(model => model.NoiDung, new { @class = "adminRichText" })
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>Giá sản phẩm</td>
                                <td>
                                    @Html.TextBoxFor(model => model.GiaBan, new { @class = "form-control focused" })
                                    @Html.ValidationMessageFor(model => model.GiaBan)
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <label class="control-label" for="focusedInput">Giá khuyễn mãi</label>
                                </td>
                                <td>
                                    @Html.TextBoxFor(model => model.GiaKM, new { @class = "form-control focused" })
                                    @Html.ValidationMessageFor(model => model.GiaKM)
                                </td>

                            </tr>
                            <tr>
                                <td>
                                    <label class="control-label" for="focusedInput">Hình ảnh đại diện</label>
                                </td>
                                <td>

                                    <div id="imagePreview">
                                        <img id="imgupload" src="/images/@Model.Image" />
                                    </div>
                                    @Html.TextBoxFor(m => m.Image, new { type = "file", @class = "imageupload" })
                                    <button class="btn" id="anhb" type="button" style="display:none">Cancel</button>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <label class="control-label" for="focusedInput">Hình ảnh Slider</label>
                                </td>
                                <td>
                                    <div id="imagePreview">
                                        <img id="imgslideupload" src="/images/@(Model.Image1 == "" ? "default.png" : Model.Image1)" />
                                    </div>
                                    @Html.TextBoxFor(m => m.Image1, new { type = "file", @class = "imgslideupload" })
                                    <button class="btn" id="anhsxoa" type="button">Xóa</button>
                                </td>
                            </tr>
                            <tr>
                                <td>Title meta</td>
                                <td>@Html.TextBoxFor(model => model.Title, new { @class = "form-control focused" })</td>

                            </tr>
                            <tr>
                                <td>Description meta</td>
                                <td>@Html.TextBoxFor(model => model.Description, new { @class = "form-control focused" })</td>
                            </tr>
                            <tr>
                                <td>Keyword meta</td>
                                <td>@Html.TextBoxFor(model => model.Keywords, new { @class = "form-control focused" })</td>
                            </tr>

                        </tbody>
                    </table>
                    <div class="form-actions">
                        <button type="submit" class="btn btn-primary">Save changes</button>
                        <button class="btn" type="reset">Cancel</button>
                    </div>

                }
            </div>
        </div>
    </div>
</div>
@section java
    {
    <!--JavaScript-->
    <script type="text/javascript" src="/content/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="/content/ckeditor/adapters/jquery.js"></script>
    <script src="/Content/ckfinder/ckfinder.js" type="text/javascript"></script>
    <style>
        .adminTichText {
            width: 100%;
        }
    </style>
    <script type="text/javascript">
        jQuery(".adminRichText").ckeditor();
    </script>
    <script type="text/javascript">
        var editor; function createEditor(languageCode, id) {
            var editor = CKEDITOR.replace(id, { language: languageCode });
        }
        $("#anhb").click(function () {
            var finder = new CKFinder();
            finder.selectActionFunction = function (fileUrl)
            { $("#Image").val(fileUrl); }; finder.popup();
        });


    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".imageupload").on("change", function () {
                var files = !!this.files ? this.files : [];
                if (!files.length || !window.FileReader) return; // no file selected, or no FileReader support

                if (/^image/.test(files[0].type)) { // only image file
                    var reader = new FileReader(); // instance of the FileReader
                    reader.readAsDataURL(files[0]); // read the local file

                    reader.onloadend = function () { // set image data as background of div
                        $("#imgupload").attr("src", this.result);
                    }
                }
            });

            $(".imgslideupload").on("change", function () {
                var files = !!this.files ? this.files : [];
                if (!files.length || !window.FileReader) return; // no file selected, or no FileReader support

                if (/^image/.test(files[0].type)) { // only image file
                    var reader = new FileReader(); // instance of the FileReader
                    reader.readAsDataURL(files[0]); // read the local file

                    reader.onloadend = function () { // set image data as background of div
                        $("#imgslideupload").attr("src", this.result);
                    }
                }
            });

            $("#anhsxoa").click(function () {
                $.ajax({
                    url: '@Url.Action("DeleteSlide")',
                    type: 'POST',
                    data: { Id: '@Model.Id' },
                    success: function (strdata) {
                        if(strdata=="true")
                        $("#imgslideupload").attr("src", "/images/default.png");

                    }
                })

            });
        });
    </script>
}
